<template>
  <el-dialog :title='titleFont' :visible.sync='isShow' width='700px' :lock-scroll=false :close-on-click-modal=false @close='clearForm("queryForm")' @open="openInitializtaion">
    <div v-loading="loading">
      <el-card class='type-info-box-card'>
        <el-form ref='queryForm' size='mini' :model="queryForm" label-width="140px" :rules="rules" label-position="center">
          <el-row :gutter="30">
            <el-col :span='100'>
              <el-form-item label='技能组名称' prop='CHLCODE'>
                <el-select v-model='queryForm.CHLCODE' filterable style="width:350px">
                  <el-option v-for='item in CHLNAMEOpions' :key='item.BUSITYPE' :label='item.BUSITYPENAME' :value='item.BUSITYPE'>
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label='交易名称' prop='FLOWID'>
                <div style="height:40px">
                </div>
                <el-transfer v-model="queryForm.FLOWID" :props="{key:'valu',label:'desc'}" :data="BUSITYPEPOOL" :titles="['交易列表','已选交易']" filter-placeholder="请选择交易" style="width:550px;margin-left: -70px; padding-bottom:10px">
                </el-transfer>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
      <div slot="footer" style="margin:10px 0;text-align:center">
        <el-button size="mini" @click="isShow=false">取消</el-button>
        <el-button type='primary' size='mini' @click="submit">确定</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
  import request from "@/common/utils/requestCT";
  import channelTransactionAdd from "@/message/CTManage/skill-transaction/skill-transaction-insert";
  import channelTransactionUpdate from "@/message/CTManage/skill-transaction/skill-transaction-update";
  import channelNameQuery from "@/message/CTManage/skill/teller-skill-query";
  import transactionNameQuery from "@/message/shared/transaction-name-query";
  export default {
    data() {
      return {
        BUSITYPEPOOL: [],
        CHLNAMEOpions:[],
        FLOWNAMEOpions:[],
        FLOWID:[],
        loading: false,
        titleFont: '技能对应交易',
        queryForm: { //表单数据
          FLOWID: [],
          CHLCODE: '',
          ID: ''
        },
        rules: { //表单校验规则
          CHLCODE: [{
            required: true,
            message: "请技能组名称",
            trigger: "change"
          }],
          FLOWID: [{
            required: true,
            message: "请选择交易名称",
            trigger: "change"
          }]
        }
      };
    },
    props: { option: Object ,message:Array },
    methods: {
         initializtaion(){
        this.queryForm.CHLCODE = this.message[0].CHLCODE;
        console.log("this.message[0].BUSITYPE;",this.message[0].BUSITYPE);
        
        this.queryForm.FLOWID = this.message[0].FLOWID.split(",");
        for(let i=0;i<this.queryForm.FLOWID.length;i++){
          this.queryForm.FLOWID[i] = parseInt(this.queryForm.FLOWID[i]);
        }
      
        // this.oldBUSITYPE = this.message[0].BUSITYPE;
    },
      //交易
      //  async transactionNameQuery() {
      //   this.loading = true;
      //   this.tableData = [];
      //   this.tableTotal = 0;
      //   let resBody = new transactionNameQuery();
      //   let response = await request(resBody);

      //   this.loading = false;
      //   if (response.SYS_HEAD.ReturnCode == "000000") {
      //     console.log(response.RSP_BODY.resultSet)
      //     this.FLOWNAMEOpions = response.RSP_BODY.resultSet;
      //     this.generateData();
      //   } else {
      //     this.$message({
      //       type: "error",
      //       message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
      //     });
      //   }
      // },
      // //技能组
      // async channelNameQuery() {
      //   this.loading = true;
      //   this.tableData = [];
      //   this.tableTotal = 0;
      //   let resBody = new channelNameQuery();
      //   let response = await request(resBody);
      //   this.loading = false;
      //   if (response.SYS_HEAD.ReturnCode == "000000") {
      //     this.CHLNAMEOpions = response.RSP_BODY.resultSet;
          
      //   } else {
      //     this.$message({
      //       type: "error",
      //       message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
      //     });
      //   }
      // },
      // generateData() {
      //   const data = [];
      //   for (let i = 0; i < this.FLOWNAMEOpions.length; i++) {
      //     data.push({
      //       valu: this.FLOWNAMEOpions[i].FLOWID,
      //       desc: this.FLOWNAMEOpions[i].FLOWNAME,
      //     })
      //   };
      //   this.BUSITYPEPOOL = data;
      //   console.log(this.BUSITYPEPOOL)
      // },
      openInitializtaion() {
        this.initializtaion()
        // this.channelNameQuery();
        // this.transactionNameQuery();
        this.titleFont = this.option.font + '技能对应交易';
        if (!this.option.currentRow.length) return;
        const {
          CHLCODE,
          FLOWID,
          ID
        } = this.option.currentRow[0]
        this.queryForm = {
          CHLCODE,
          FLOWID,
          ID
        }
      },
      submit() {
        //添加策略事件
        this.$refs["queryForm"].validate(valid => {
          if (valid) {
            this.loading = true;
            let resBody;
            if (this.option.isUpdate) {
              resBody = new channelTransactionUpdate();
              resBody.data.ID = this.queryForm.ID;
            } else {
              resBody = new channelTransactionAdd();
            }
            resBody.data.FLOWID = this.queryForm.FLOWID;
            resBody.data.BUSITYPE = this.queryForm.CHLCODE;
            request(resBody)
              .then(response => {
                this.loading = false;
                if (response.SYS_HEAD.ReturnCode === "000000") {
                  this.$message({
                    type: "success",
                    message: this.option.isUpdate ? "技能对应交易更新成功!" : "技能对应交易新增成功!"
                  });
                  this.isShow = false;
                  this.$emit("refreshTable");
                } else {
                  this.$message({
                    type: "error",
                    message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
                  });
                }
              })
              .catch(error => {
                this.loading = false;
                console.log(error);
              });
          }
        });
      },
      clearForm(item) {
        if (this.$refs.queryForm) {
          this.$refs.queryForm.resetFields();
          this.$refs.queryForm.clearValidate();
        }
      }
    },
    computed: {
      isShow: {
        get: function() {
          return this.option.isShow;
        },
        set: function(newValue) {
          this.option.isShow = newValue;
        }
      }
      // CHLNAMEOpions: function() {
      //   return this.option.CHLNAMEOpions
      // },
      // FLOWNAMEOpions: function() {
      //   return this.option.FLOWNAMEOpions
      // }
    },
    async created() {}
    // mounted() {
    //   window.addEventListener("scroll", this.handleScroll);
    // }
  };
</script>

<style lang="scss" scope>

</style>
